home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / cport20.zip / CPORT.H < prev    next >
C/C++ Source or Header  |  1993-04-09  |  11KB  |  470 lines

  1. /*
  2. // CPORT.H
  3. //
  4. // Header file for Cport Communications Library
  5. //
  6. // Copyright (c) 1993 Bri Productions
  7. //
  8. */
  9.  
  10. #ifndef _CPORT_H_
  11. #define _CPORT_H_
  12.  
  13. #include "stddef.h"
  14.  
  15. #if defined  __TURBOC__
  16. # if  __STDC__
  17. #  define  _Cdecl
  18. # else
  19. #  define  _Cdecl  cdecl
  20. # endif
  21. #elif defined  __ZTC__
  22. # define  _Cdecl
  23. #elif defined  M_I86 && !defined  __ZTC__
  24. # if !defined NO_EXT_KEYS
  25. #  define  _Cdecl  cdecl
  26. # else
  27. #  define  _Cdecl
  28. # endif
  29. #else
  30. #define  _Cdecl
  31. #endif
  32.  
  33.  
  34.  
  35. /*
  36. //-------------------------------------
  37. //
  38. // com port id's
  39. //
  40. //-------------------------------------
  41. */
  42.  
  43. #define  PORT0 0x03F8                  /* hard port addresses  */
  44. #define  PORT1 0x02F8
  45. #define  PORT2 0x03E8
  46. #define  PORT3 0x02E8
  47.  
  48. #define  BIOS0 (*(int far *)0x400000l) /* bios port addresses  */
  49. #define  BIOS1 (*(int far *)0x400002l)
  50. #define  BIOS2 (*(int far *)0x400004l)
  51. #define  BIOS3 (*(int far *)0x400006l)
  52.  
  53. #define  IRQ2  0x2000                  /* irq's                */
  54. #define  IRQ3  0x3000
  55. #define  IRQ4  0x4000
  56. #define  IRQ5  0x5000
  57. #define  IRQ6  0x6000
  58. #define  IRQ7  0x7000
  59.  
  60. #define  COM1  (PORT0 | IRQ4)          /* hard 'com' ports     */
  61. #define  COM2  (PORT1 | IRQ3)
  62. #define  COM3  (PORT2 | IRQ4)
  63. #define  COM4  (PORT3 | IRQ3)
  64.                                        /* bios 'com' ports     */
  65.  
  66. #define  BCOM1 ((BIOS0 | 0x1000) + ((BIOS0 << 4) & 0xf000))
  67. #define  BCOM2 ((BIOS1 | 0x1000) + ((BIOS1 << 4) & 0xf000))
  68. #define  BCOM3 ((BIOS2 | 0x1000) + ((BIOS2 << 4) & 0xf000))
  69. #define  BCOM4 ((BIOS3 | 0x1000) + ((BIOS3 << 4) & 0xf000))
  70.  
  71.  
  72. /*
  73. //-------------------------------------
  74. //
  75. // baud rate divisors
  76. //
  77. //-------------------------------------
  78. */
  79.  
  80. #define  B115200  1
  81. #define  B57600   2
  82. #define  B38400   3
  83. #define  B19200   6
  84. #define  B9600    12
  85. #define  B7200    16
  86. #define  B4800    24
  87. #define  B3600    32
  88. #define  B2400    48
  89. #define  B2000    58
  90. #define  B1800    64
  91. #define  B1200    96
  92. #define  B600     192
  93. #define  B300     384
  94. #define  B150     768
  95. #define  B110     1047
  96. #define  B75      1536
  97. #define  B50      2304
  98.  
  99.  
  100. /*
  101. //-------------------------------------
  102. //
  103. // word lengths
  104. //
  105. //-------------------------------------
  106. */
  107.  
  108. #define  W8    3
  109. #define  W7    2
  110. #define  W6    1
  111. #define  W5    0
  112. #define  WMASK 3
  113.  
  114.  
  115. /*
  116. //-------------------------------------
  117. //
  118. // stop bits
  119. //
  120. //-------------------------------------
  121. */
  122.  
  123. #define  S1    0
  124. #define  S2    4
  125. #define  SMASK 4
  126.  
  127.  
  128. /*
  129. //-------------------------------------
  130. //
  131. // parity
  132. //
  133. //-------------------------------------
  134. */
  135.  
  136. #define  NONE     0x00
  137. #define  ODD      0x08
  138. #define  EVEN     0x18
  139. #define  MARK     0x28
  140. #define  SPACE    0x38
  141. #define  PMASK    0x38
  142.  
  143.  
  144. /*
  145. //-------------------------------------
  146. //
  147. // handshaking
  148. //
  149. //-------------------------------------
  150. */
  151.  
  152. #define  DTR      0x001
  153. #define  RTS      0x002
  154. #define  S_RX     0x004
  155. #define  S_TX     0x008
  156. #define  CTS      0x010
  157. #define  DSR      0x020
  158. #define  DCD      0x080
  159.  
  160. #define  SOFT     ((S_RX) | (S_TX))
  161. #define  HARD     ((RTS)| (CTS))
  162. #define  HARD1    ((DTR)| (DSR))
  163. #define  HARD2    ((RTS)| (CTS))
  164.  
  165.  
  166. /*
  167. //-------------------------------------
  168. //
  169. // error codes
  170. //
  171. //-------------------------------------
  172. */
  173.  
  174. #define  OVERUN    0x002         /* overrun error           */
  175. #define  PARITY    0x004         /* parity error            */
  176. #define  FRAMING   0x008         /* framing error           */
  177. #define  BREAK     0x010         /* break detect            */
  178. #define  RX_FIFO   0x080         /* error in recieve fifo   */
  179. #define  TXFULL    0x100         /* transmit queue overflow */
  180. #define  RXFULL    0x200         /* receive queue overflow  */
  181.  
  182.  
  183. /*
  184. //-------------------------------------
  185. //
  186. // status codes
  187. //
  188. //-------------------------------------
  189. */
  190.  
  191. #define  DCTS        0x001       /* delta clear to send           */
  192. #define  DDSR        0x002       /* delta data set ready          */
  193. #define  TERI        0x004       /* trailing edge ring  indicator */
  194. #define  DDCD        0x008       /* delta data carrier detect     */
  195. #define  CTS         0x010       /* clear to send                 */
  196. #define  DSR         0x020       /* data set ready                */
  197. #define  RI          0x040       /* ring indicator                */
  198. #define  DCD         0x080       /* data carrier detect           */
  199.  
  200. #define  S_TX_OFF    0x0100      /* software transmit off         */
  201. #define  U_TX_OFF    0x0200      /* user transmit off             */
  202. #define  S_RX_OFF    0x0400      /* software receive off          */
  203. #define  X_REQST     0x0800      /* send XON/XOFF request         */
  204. #define  X_SENT      0x1000      /* X character send (TX_DIRECT)  */
  205. #define  U_TX_DIR    0x2000      /* In direct transmit mode       */
  206.  
  207. /*
  208. //-------------------------------------
  209. // 
  210. // Uart types ComUart
  211. //
  212. //-------------------------------------
  213. */
  214.                                                                         
  215. #define  INS8250   1             /* INS8250/INS8250-B                   */
  216. #define  NS16450   2             /* INS8250A/NS16450/NS16C450/NS16C450A */
  217. #define  NS16550   3             /* NS16550                             */
  218. #define  I82510    4             /* 82510 (Intel)                       */
  219.  
  220.  
  221. /*
  222. //-------------------------------------
  223. //
  224. // ComTurbo options
  225. //
  226. //-------------------------------------
  227. */
  228.  
  229. #define  TIMER       0x01     /* timer bit (irq0)              */
  230. #define  KEYBOARD    0x02     /* keyboard bit (irq1)           */
  231. #define  CASCADE     0x04     /* cascade/reserved bit (irq2)   */
  232.  
  233.  
  234. /*
  235. //-------------------------------------
  236. //
  237. // NS16550 rx FIFO trigger levels
  238. //
  239. //-------------------------------------
  240. */
  241.  
  242. #define  T550_1      0x00
  243. #define  T550_4      0x40
  244. #define  T550_8      0x80
  245. #define  T550_14     0xC0
  246.  
  247.  
  248. /*
  249. //-------------------------------------
  250. //
  251. //
  252. //
  253. //-------------------------------------
  254. */
  255.  
  256. /*
  257. //-------------------------------------
  258. //
  259. // typedefs and structures
  260. //
  261. //-------------------------------------
  262. */
  263.  
  264. #ifndef _BYTE_
  265. #define _BYTE_
  266. typedef unsigned char byte;
  267. #endif
  268.  
  269.     /* Make sure this structure is byte packed
  270.     */
  271.  
  272. #ifdef M_I86
  273. #pragma pack(1) 
  274. #endif
  275.  
  276.    /** Do not change this structure **/
  277.  
  278. struct C_param{
  279.    unsigned id;               /* com port id                      */
  280.    int      baud;             /* baud rate                        */
  281.    byte     mode;             /* word length, stop bits, parity   */
  282.    unsigned rxQ;              /* receive queue size               */
  283.    unsigned txQ;              /* transmit queue size              */
  284.    byte     htype;            /* handshaking type                 */
  285.    unsigned thresh;           /* handshaking threshold (rx queue) */
  286.    };
  287.  
  288. typedef struct C_param CPARAM;
  289. typedef void* COM;
  290.  
  291. #ifdef M_I86
  292. #pragma pack() 
  293. #endif
  294.  
  295. /*
  296. //-------------------------------------
  297. //
  298. // Misc
  299. //
  300. //-------------------------------------
  301. */
  302.  
  303. enum { OFF  , ON   };
  304. #define TX_DIRECT    0x20
  305.  
  306.  
  307. /*
  308. //-------------------------------------
  309. //
  310. // comopen_errno
  311. //
  312. //-------------------------------------
  313. */
  314.  
  315. #define  NO_ERR   0        /* no error                         */
  316. #define  OPENED   1        /* port already opened              */
  317. #define  BAD_ID   2        /* bad id parameter                 */
  318. #define  NO_UART  3        /* no uart chip found               */
  319. #define  RX_ALC   4        /* receive queue allocation error   */
  320. #define  TX_ALC   5        /* transmit queue allocation error  */
  321. #define  MAX_PORT 6        /* max number of com ports opened   */
  322. #define  IRQ_CTN  7        /* interrupt contention             */
  323. #define  GEN_ALC  8        /* general allocation error         */
  324.  
  325.  
  326. /*
  327. //-------------------------------------
  328. //
  329. // function macros
  330. //
  331. //-------------------------------------
  332. */
  333.  
  334. #define  ComOut1(c,a)         ComMcr(c,a, 0x04)
  335. #define  ComRts(c,a)          ComMcr(c,a, 0x02)
  336. #define  ComDtr(c,a)          ComMcr(c,a, 0x01)
  337.  
  338.  
  339. /*
  340. //-------------------------------------
  341. //
  342. // function prototypes
  343. //
  344. //-------------------------------------
  345. */
  346.  
  347. #ifdef __cplusplus
  348. extern "C" {
  349. #endif
  350.  
  351.    /* control functions */
  352.  
  353. COM      _Cdecl   ComOpen        (unsigned id, int baud, byte mode, unsigned rxQ, unsigned txQ);
  354. COM      _Cdecl   ComOpenS       (const CPARAM* param);
  355. COM      _Cdecl   ComClose       (COM com);
  356. void     _Cdecl   ComHandshake   (COM com, byte htype, unsigned thresh);
  357. void     _Cdecl   ComParam       (COM com, CPARAM* param);
  358. void     _Cdecl   ComBaud        (COM com, int baud);
  359. void     _Cdecl   ComMode        (COM com, byte mode);
  360. int      _Cdecl   ComTx          (COM com, int cmnd);
  361. void     _Cdecl   ComTurbo       (int options);
  362. void     _Cdecl   ComCloseAll    (void);
  363. void     _Cdecl   ComNS550       (COM com, int trigger);
  364. unsigned _Cdecl   ComRxQ         (COM com, unsigned size);
  365. unsigned _Cdecl   ComTxQ         (COM com, unsigned size);
  366.  
  367.  
  368.    /* input functions    */
  369.  
  370. char     _Cdecl   ComGetc        (COM com);
  371. unsigned _Cdecl   ComLenRx       (COM com);
  372. char    *_Cdecl   ComGets        (COM com, char *str, int maxc, char termc);
  373. unsigned _Cdecl   ComIn          (COM com, void *abyte, unsigned nbyte);
  374. void     _Cdecl   ComFlushRx     (COM com);
  375. char     _Cdecl   ComPeek        (COM com);
  376. unsigned _Cdecl   ComRxScan      (COM com, char c);
  377.  
  378.  
  379.    /* output functions  */
  380.  
  381. int      _Cdecl   ComPutc        (COM com, char c);
  382. unsigned _Cdecl   ComLenTx       (COM com);
  383. int      _Cdecl   ComPuts        (COM com, const char *str);
  384. unsigned _Cdecl   ComOut         (COM com, const void *abyte, unsigned nbyte);
  385. void     _Cdecl   ComFlushTx     (COM com);
  386. void     _Cdecl   ComTxWait      (COM com);
  387.  
  388.  
  389.    /* status functions  */
  390.  
  391. void     _Cdecl   ComMcr         (COM com, byte on_off, byte bits);
  392. unsigned _Cdecl   ComError       (COM com);
  393. unsigned _Cdecl   ComStatus      (COM com);
  394. int      _Cdecl   ComUart        (COM com);
  395.  
  396.  
  397.    /* misc fuctions  */
  398.  
  399. void     _Cdecl   ComSetBreak    (COM com);
  400. void     _Cdecl   ComClrBreak    (COM com);
  401. void     _Cdecl   ComPutScrtch   (COM com, byte abyte);
  402. byte     _Cdecl   ComGetScrtch   (COM com);
  403.  
  404.  
  405.    /* data integrity functions   */
  406.  
  407. byte          _Cdecl ComChecksum (const void *abyte, unsigned nbyte);
  408. unsigned      _Cdecl ComCrc16    (const void *abyte, unsigned nbyte);
  409. unsigned long _Cdecl ComCrc32    (const void *abyte, unsigned nbyte);
  410.  
  411.  
  412.    /* debug */
  413.  
  414. COM      _Cdecl   ComHandle      (COM com);
  415.  
  416.  
  417. #ifdef __cplusplus
  418. }           /* extern "C" */
  419. #endif
  420.  
  421.  
  422.  
  423. /*
  424. //-------------------------------------
  425. //
  426. // comopen_errno 
  427. //
  428. //-------------------------------------
  429. */
  430.  
  431.  
  432. #ifdef __cplusplus
  433. extern "C" int   comopen_errno;
  434. #else
  435. extern   int   comopen_errno;
  436. #endif
  437.  
  438.  
  439.  
  440. /*
  441. //-------------------------------------
  442. //
  443. // Other header files
  444. //
  445. //-------------------------------------
  446. */
  447.  
  448.    /* Implicit and explicit C++ inclusion
  449.    */
  450. #ifdef __cplusplus
  451. #include   "cport.hpp"
  452. #endif
  453.  
  454.  
  455.    /* Xmodem inclusion
  456.    */
  457. #ifdef Uses_Xmodem
  458. #include "xmodem.h"
  459. #endif
  460.  
  461.    /* Zmodem inclusion
  462.    */
  463. #ifdef Uses_Zmodem
  464. #include "zmodem.h"     /* Not yet implemented  */
  465. #endif
  466.  
  467.  
  468. #endif      /* CPORT.H */
  469.  
  470.